package com.start.form.engine.core.configs;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "start.form.share")
public class StartFormShareConfig {
    /**
     * 客户端上下文路径
     */
    @Schema(name = "客户端上下文路径")
    private String mobileContextPath;
    @Schema(name = "客户端host")
    private String mobileRootHost;
    @Schema(name = "客户端端口")
    private Integer mobilePort = 80;
    @Schema(name = "其他地址")
    private String otherUrl;
    @Schema(name = "关键字")
    private String key;

    public String getMobileUrl(String keyValue) {
        StringBuilder builder = new StringBuilder();
        builder.append(mobileRootHost);
        if (mobilePort != null) {
            builder.append(":").append(mobilePort);
        }
        if (!StringUtils.isEmpty(mobileContextPath)) {
            builder.append(mobileContextPath);
        }
        if (!StringUtils.isEmpty(otherUrl)) {
            builder.append(otherUrl);
        }
        if (StringUtils.isEmpty(key)) return builder.toString();
        return builder.toString().replace(key, keyValue);
    }
}
